package com.lichuandi.future;

import java.util.concurrent.CompletableFuture;

public class CompletableFutureExample {
    public static void main(String[] args) {
        CompletableFuture.supplyAsync(() -> "Hello")
                .thenApplyAsync(s -> s + " World") // 异步拼接
                .thenAcceptAsync(System.out::println) // 异步消费
                .exceptionally(ex -> { // 异常处理
                    System.out.println("Error: " + ex.getMessage());
                    return null;
                });
        System.out.println("主线程继续执行");
    }
}
